package com.warm.pump.module.monitor.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.monitor.bean.po.gen.MonitorCache;
import com.warm.pump.module.monitor.mapper.gen.MonitorCacheMapper;
import com.warm.pump.module.monitor.bean.po.gen.MonitorCacheExample;
@Repository
public class MonitorCacheDao {
	// 日志对象
	private transient Log log = LogFactory.getLog(this.getClass());
	@Autowired
	private MonitorCacheMapper monitorCacheMapper;

	// 增加一个后台MonitorCache表
	
	public boolean insert(MonitorCache monitorCache) {
		try {
			monitorCacheMapper.insert(monitorCache);
			log.debug("后台MonitorCache表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台MonitorCache表增加失败");
			throw new ServiceException("后台MonitorCache表增加失败",e);
		}
	}
	// 增加一个后台MonitorCache表Selective
	
	public boolean insertSelective(MonitorCache monitorCache) {
		try {
			monitorCacheMapper.insertSelective(monitorCache);
			log.debug("后台MonitorCache表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台MonitorCache表增加失败");
			throw new ServiceException("后台MonitorCache表增加失败",e);
		}
	}

	// 删除一个后台MonitorCache表
	
	public boolean deleteByPrimaryKey(Long id) {
		try{
			monitorCacheMapper.deleteByPrimaryKey(id);
			log.debug("后台MonitorCache表删除成功");
			return true;
		} catch(Exception e){
			log.debug("后台MonitorCache表删除失败");
			throw new ServiceException("后台MonitorCache表删除失败",e);
		}
	}
	// 删除一个后台MonitorCache表byMap
	
	public boolean deleteByMap(Map monitorCacheMap) {
		try{
			monitorCacheMapper.deleteByExample(createMonitorCacheExample(monitorCacheMap,null,null));
			log.debug("后台MonitorCache根据Map删除成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台MonitorCache根据GroupID删除失败");
			throw new ServiceException("后台MonitorCache根据object删除失败",e);
		}
	}
	// 修改一个后台MonitorCache表
	
	public boolean updateByPrimaryKey(MonitorCache monitorCache) {
		try{
			monitorCacheMapper.updateByPrimaryKey(monitorCache);
			log.debug("后台MonitorCache表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台MonitorCache表修改失败");
			throw new ServiceException("后台MonitorCache表修改失败",e);
		}
	}
	// 修改一个后台MonitorCache表Selective
	
	public boolean updateByPrimaryKeySelective(MonitorCache monitorCache) {
		try{
			monitorCacheMapper.updateByPrimaryKeySelective(monitorCache);
			log.debug("后台MonitorCache表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台MonitorCache表修改失败");
			throw new ServiceException("后台MonitorCache表修改失败",e);
		}
	}
	// 修改一个后台MonitorCache表
	
	public boolean updateByMap(MonitorCache monitorCache,Map monitorCacheMap) {
		try{
			monitorCacheMapper.updateByExample(monitorCache,createMonitorCacheExample(monitorCacheMap,null,null));
			log.debug("后台批量MonitorCache表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量MonitorCache表修改失败");
			throw new ServiceException("后台MonitorCache表批量修改失败",e);
		}
	}
	// 修改一个后台MonitorCache表Selective
	
	public boolean updateByMapSelective(MonitorCache monitorCache,Map monitorCacheMap) {
		try{
			monitorCacheMapper.updateByExampleSelective(monitorCache,createMonitorCacheExample(monitorCacheMap,null,null));
			log.debug("后台批量MonitorCache表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量MonitorCache表修改失败");
			throw new ServiceException("后台MonitorCache表批量修改失败",e);
		}
	}

	// 查询一个后台MonitorCache表
	
	public MonitorCache selectByPrimaryKey(Long id) {
		return monitorCacheMapper.selectByPrimaryKey(id);
	}
	
	// 查询一个后台MonitorCache表-根据map
	
	public MonitorCache selectByMap(Map monitorCacheMap) {
		List<MonitorCache> list = getListByMap(monitorCacheMap);
		if(list==null||list.isEmpty()){
			return null;
		}else{
			return list.get(0);
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 查询所有后台MonitorCache表
	
	public List<MonitorCache> getListByMap(Map monitorCacheMap) {
		
		return monitorCacheMapper.selectByExample(createMonitorCacheExample(monitorCacheMap,null,null));
	}

	//统计后台MonitorCache表数量
	
	public int countTotalByMap(Map monitorCacheMap) {
		
		return monitorCacheMapper.countByExample(createMonitorCacheExample(monitorCacheMap,null,null));
	}

	
	public List<MonitorCache> getListByMapPage(Map monitorCacheMap, int limitStart,
			int limitOffset) {
		
		return monitorCacheMapper.selectByExample(createMonitorCacheExample(monitorCacheMap,limitStart,limitOffset));
	}
	
	
	public PageBean getPageBeanByMap(Map monitorCacheMap,int pageNo,int pageSize) {
		Integer count = countTotalByMap(monitorCacheMap);
		PageBean pageBean = new PageBean();
		pageBean.setCount(count);
		pageBean.setPageNo(pageNo);
		pageBean.setPageSize(pageSize);
		int limitStart = pageBean.getStartNo();
		int limitOffset = pageSize;
		pageBean.setData(monitorCacheMapper.selectByExample(createMonitorCacheExample(monitorCacheMap,limitStart,limitOffset)));
		return pageBean;
	}
		
	private MonitorCacheExample createMonitorCacheExample(Map monitorCacheMap,Integer limitStart,Integer limitOffset){
			MonitorCacheExample monitorCacheEx = new MonitorCacheExample();
			MonitorCacheExample.Criteria c = monitorCacheEx.createCriteria();
				Long id_null = TypeCast.getLong(monitorCacheMap.get("id_null"));
				Long id_notNull = TypeCast.getLong(monitorCacheMap.get("id_notNull"));
				Long id = TypeCast.getLong(monitorCacheMap.get("id"));
				Long id_not = TypeCast.getLong(monitorCacheMap.get("id_not"));
				Long id_greater = TypeCast.getLong(monitorCacheMap.get("id_greater"));
				Long id_greaterEqual = TypeCast.getLong(monitorCacheMap.get("id_greaterEqual"));
				Long id_less = TypeCast.getLong(monitorCacheMap.get("id_less"));
				Long id_lessEqual = TypeCast.getLong(monitorCacheMap.get("id_lessEqual"));
				List<Long> id_in = TypeCast.getLongList(monitorCacheMap.get("id_in"));
				List<Long> id_notIn = TypeCast.getLongList(monitorCacheMap.get("id_notIn"));
				Long id_between1 = TypeCast.getLong(monitorCacheMap.get("id_between1"));
				Long id_between2 = TypeCast.getLong(monitorCacheMap.get("id_between2"));
				Long id_notBetween1 = TypeCast.getLong(monitorCacheMap.get("id_notBetween1"));
				Long id_notBetween2 = TypeCast.getLong(monitorCacheMap.get("id_notBetween2"));
				
				if(id_null != null){
					c.andIdIsNull();
				}
				if(id_notNull != null){
					c.andIdIsNotNull();
				}
				if(id != null){
					c.andIdEqualTo(id);
				}
				if(id_not != null){
					c.andIdNotEqualTo(id_not);
				}
				if(id_greater != null){
					c.andIdGreaterThan(id_greater);
				}
				if(id_greaterEqual != null){
					c.andIdGreaterThanOrEqualTo(id_greaterEqual);
				}
				if(id_less != null){
					c.andIdLessThan(id_less);
				}
				if(id_lessEqual != null){
					c.andIdLessThanOrEqualTo(id_lessEqual);
				}
				if(id_in != null){
					c.andIdIn(id_in);
				}
				if(id_notIn != null){
					c.andIdNotIn(id_notIn);
				}
				if(id_between1 != null){
					c.andIdBetween(id_between1,id_between2);
				}
				if(id_notBetween1 != null){
					c.andIdNotBetween(id_notBetween1,id_notBetween2);
				}
				String cacheName_null = TypeCast.getString(monitorCacheMap.get("cacheName_null"));
				String cacheName_notNull = TypeCast.getString(monitorCacheMap.get("cacheName_notNull"));
				String cacheName = TypeCast.getString(monitorCacheMap.get("cacheName"));
				String cacheName_not = TypeCast.getString(monitorCacheMap.get("cacheName_not"));
				String cacheName_greater = TypeCast.getString(monitorCacheMap.get("cacheName_greater"));
				String cacheName_greaterEqual = TypeCast.getString(monitorCacheMap.get("cacheName_greaterEqual"));
				String cacheName_less = TypeCast.getString(monitorCacheMap.get("cacheName_less"));
				String cacheName_lessEqual = TypeCast.getString(monitorCacheMap.get("cacheName_lessEqual"));
				String cacheName_like = TypeCast.getString(monitorCacheMap.get("cacheName_like"));
				String cacheName_notLike = TypeCast.getString(monitorCacheMap.get("cacheName_notLike"));
				List<String> cacheName_in = TypeCast.getStringList(monitorCacheMap.get("cacheName_in"));
				List<String> cacheName_notIn = TypeCast.getStringList(monitorCacheMap.get("cacheName_notIn"));
				String cacheName_between1 = TypeCast.getString(monitorCacheMap.get("cacheName_between1"));
				String cacheName_between2 = TypeCast.getString(monitorCacheMap.get("cacheName_between2"));
				String cacheName_notBetween1 = TypeCast.getString(monitorCacheMap.get("cacheName_notBetween1"));
				String cacheName_notBetween2 = TypeCast.getString(monitorCacheMap.get("cacheName_notBetween2"));
				
				if(cacheName_null != null){
					c.andCacheNameIsNull();
				}
				if(cacheName_notNull != null){
					c.andCacheNameIsNotNull();
				}
				if(cacheName != null){
					c.andCacheNameEqualTo(cacheName);
				}
				if(cacheName_not != null){
					c.andCacheNameNotEqualTo(cacheName_not);
				}
				if(cacheName_greater != null){
					c.andCacheNameGreaterThan(cacheName_greater);
				}
				if(cacheName_greaterEqual != null){
					c.andCacheNameGreaterThanOrEqualTo(cacheName_greaterEqual);
				}
				if(cacheName_less != null){
					c.andCacheNameLessThan(cacheName_less);
				}
				if(cacheName_lessEqual != null){
					c.andCacheNameLessThanOrEqualTo(cacheName_lessEqual);
				}
				if(cacheName_like != null){
					c.andCacheNameLike(cacheName_like);
				}
				if(cacheName_notLike != null){
					c.andCacheNameNotLike(cacheName_notLike);
				}
				if(cacheName_in != null){
					c.andCacheNameIn(cacheName_in);
				}
				if(cacheName_notIn != null){
					c.andCacheNameNotIn(cacheName_notIn);
				}
				if(cacheName_between1 != null){
					c.andCacheNameBetween(cacheName_between1,cacheName_between2);
				}
				if(cacheName_notBetween1 != null){
					c.andCacheNameNotBetween(cacheName_notBetween1,cacheName_notBetween2);
				}
				Date startDate_null = TypeCast.getDate(monitorCacheMap.get("startDate_null"));
				Date startDate_notNull = TypeCast.getDate(monitorCacheMap.get("startDate_notNull"));
				Date startDate = TypeCast.getDate(monitorCacheMap.get("startDate"));
				Date startDate_not = TypeCast.getDate(monitorCacheMap.get("startDate_not"));
				Date startDate_greater = TypeCast.getDate(monitorCacheMap.get("startDate_greater"));
				Date startDate_greaterEqual = TypeCast.getDate(monitorCacheMap.get("startDate_greaterEqual"));
				Date startDate_less = TypeCast.getDate(monitorCacheMap.get("startDate_less"));
				Date startDate_lessEqual = TypeCast.getDate(monitorCacheMap.get("startDate_lessEqual"));
				List<Date> startDate_in = TypeCast.getDateList(monitorCacheMap.get("startDate_in"));
				List<Date> startDate_notIn = TypeCast.getDateList(monitorCacheMap.get("startDate_notIn"));
				Date startDate_between1 = TypeCast.getDate(monitorCacheMap.get("startDate_between1"));
				Date startDate_between2 = TypeCast.getDate(monitorCacheMap.get("startDate_between2"));
				Date startDate_notBetween1 = TypeCast.getDate(monitorCacheMap.get("startDate_notBetween1"));
				Date startDate_notBetween2 = TypeCast.getDate(monitorCacheMap.get("startDate_notBetween2"));
				
				if(startDate_null != null){
					c.andStartDateIsNull();
				}
				if(startDate_notNull != null){
					c.andStartDateIsNotNull();
				}
				if(startDate != null){
					c.andStartDateEqualTo(startDate);
				}
				if(startDate_not != null){
					c.andStartDateNotEqualTo(startDate_not);
				}
				if(startDate_greater != null){
					c.andStartDateGreaterThan(startDate_greater);
				}
				if(startDate_greaterEqual != null){
					c.andStartDateGreaterThanOrEqualTo(startDate_greaterEqual);
				}
				if(startDate_less != null){
					c.andStartDateLessThan(startDate_less);
				}
				if(startDate_lessEqual != null){
					c.andStartDateLessThanOrEqualTo(startDate_lessEqual);
				}
				if(startDate_in != null){
					c.andStartDateIn(startDate_in);
				}
				if(startDate_notIn != null){
					c.andStartDateNotIn(startDate_notIn);
				}
				if(startDate_between1 != null){
					c.andStartDateBetween(startDate_between1,startDate_between2);
				}
				if(startDate_notBetween1 != null){
					c.andStartDateNotBetween(startDate_notBetween1,startDate_notBetween2);
				}
				Date expireDate_null = TypeCast.getDate(monitorCacheMap.get("expireDate_null"));
				Date expireDate_notNull = TypeCast.getDate(monitorCacheMap.get("expireDate_notNull"));
				Date expireDate = TypeCast.getDate(monitorCacheMap.get("expireDate"));
				Date expireDate_not = TypeCast.getDate(monitorCacheMap.get("expireDate_not"));
				Date expireDate_greater = TypeCast.getDate(monitorCacheMap.get("expireDate_greater"));
				Date expireDate_greaterEqual = TypeCast.getDate(monitorCacheMap.get("expireDate_greaterEqual"));
				Date expireDate_less = TypeCast.getDate(monitorCacheMap.get("expireDate_less"));
				Date expireDate_lessEqual = TypeCast.getDate(monitorCacheMap.get("expireDate_lessEqual"));
				List<Date> expireDate_in = TypeCast.getDateList(monitorCacheMap.get("expireDate_in"));
				List<Date> expireDate_notIn = TypeCast.getDateList(monitorCacheMap.get("expireDate_notIn"));
				Date expireDate_between1 = TypeCast.getDate(monitorCacheMap.get("expireDate_between1"));
				Date expireDate_between2 = TypeCast.getDate(monitorCacheMap.get("expireDate_between2"));
				Date expireDate_notBetween1 = TypeCast.getDate(monitorCacheMap.get("expireDate_notBetween1"));
				Date expireDate_notBetween2 = TypeCast.getDate(monitorCacheMap.get("expireDate_notBetween2"));
				
				if(expireDate_null != null){
					c.andExpireDateIsNull();
				}
				if(expireDate_notNull != null){
					c.andExpireDateIsNotNull();
				}
				if(expireDate != null){
					c.andExpireDateEqualTo(expireDate);
				}
				if(expireDate_not != null){
					c.andExpireDateNotEqualTo(expireDate_not);
				}
				if(expireDate_greater != null){
					c.andExpireDateGreaterThan(expireDate_greater);
				}
				if(expireDate_greaterEqual != null){
					c.andExpireDateGreaterThanOrEqualTo(expireDate_greaterEqual);
				}
				if(expireDate_less != null){
					c.andExpireDateLessThan(expireDate_less);
				}
				if(expireDate_lessEqual != null){
					c.andExpireDateLessThanOrEqualTo(expireDate_lessEqual);
				}
				if(expireDate_in != null){
					c.andExpireDateIn(expireDate_in);
				}
				if(expireDate_notIn != null){
					c.andExpireDateNotIn(expireDate_notIn);
				}
				if(expireDate_between1 != null){
					c.andExpireDateBetween(expireDate_between1,expireDate_between2);
				}
				if(expireDate_notBetween1 != null){
					c.andExpireDateNotBetween(expireDate_notBetween1,expireDate_notBetween2);
				}
			if(monitorCacheMap.get("orderBy")!=null){
				monitorCacheEx.setOrderByClause((String)monitorCacheMap.get("orderBy"));
			}
			if(limitStart != null && limitOffset != null){
				monitorCacheEx.setLimitStart(limitStart);
				monitorCacheEx.setLimitOffset(limitOffset);
			}
			
			return monitorCacheEx;
	}
}
